﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO;
using StattiLibrary;

namespace StattiLoadAssembliesPoC
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        private const string PluginsPath = "Plugins/";

        public Window1()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Post a new entry to all supported services.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            PluginManager.Post(messageTextBox.Text, usernameTextBox.Text, passwordBox.Password);
        }

        /// <summary>
        /// Show all the plugins alredy loaded.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button3_Click(object sender, RoutedEventArgs e)
        {
            List<Plugin> plugins = PluginManager.GetPlugins();
            foreach (Plugin plugin in plugins)
            {
                Console.WriteLine("Name: {0}", plugin.Name);
                Console.WriteLine("Author: {0}", plugin.Author);
                Console.WriteLine("Description: {0}", plugin.Description);
                Console.WriteLine("Version: {0}", plugin.Version);
            }

        }

        /// <summary>
        /// Loads a new plugin into the system.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.Forms.OpenFileDialog openFileDialog1 = new System.Windows.Forms.OpenFileDialog();

            openFileDialog1.InitialDirectory = Directory.GetCurrentDirectory();
            openFileDialog1.Filter = "Dll files (*.dll)|*.dll";
            openFileDialog1.FilterIndex = 2;
            openFileDialog1.RestoreDirectory = true;
            if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                PluginManager.AddPlugin(openFileDialog1.FileName);
            }
        }
    }
}
